<template>
    <div>
        <script id="editor" type="text/plain" />
    </div>
</template>

<script>
import { host } from '../../config/index.js';
import Cookies from 'js-cookie';
// 百度编辑器
import '../../../static/ueditor/ueditor.config.js';
import '../../../static/ueditor/ueditor.all.js';
import '../../../static/ueditor/lang/zh-cn/zh-cn.js';
// import '../../../static/ueditor/ueditor.parse.min.js';
import '../../../static/ueditor/themes/default/css/ueditor.css'
export default {
    name: "UEditor",
    props: {
        initData: {
            type: String,
            default: ''
        },
        config: {
            type: Object,
            default: function() {
            	return {
            		serverUrl: host + '/attachmentApi/ueupload',
            		enableAutoSave: false,
			        autoHeightEnabled: false,
			        initialFrameHeight: 350,
			        initialFrameWidth: '100%',
			        toolbars: [[
			            'fullscreen', 'source', '|', 'undo', 'redo', '|',
			            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
			            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
			            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
			            'directionalityltr', 'directionalityrtl', 'indent', '|',
			            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
			            'link', 'unlink', 'anchor', '|',
			            'insertimage', 'emotion', '|',
			            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',
			            'print', 'preview', 'searchreplace', 'help'
			        ]],	
			        xssFilterRules: false,
			        zIndex: 7
            	}
            }
        }
    },
    data() {
        return {
            editor: null
        };
    },
    methods: {
    	init(content, type = 1) {
	      	this.editor = UE.getEditor('editor', this.config);
	      	this.editor.ready(() => {
	      		this.editor.setContent(content || '')
	      	})
	      	/*
            const _this = this;
            this.editor = window.UE.getEditor("editors", this.config); // 初始化UE
            if(type == 1){
                this.editor.addListener("ready", function() {
                    _this.editor.setContent(content);
                });
            } else {
                _this.editor.setContent(content);
            }*/
    	},
        getUEditor() {
            return this.editor;
        },
        getUEContent() {
            // 获取内容方法
            return this.editor.getContent();
        }
    },
    destroyed() {
    	if(this.editor) {
    		this.editor.destroy();
    	}
    },
};
</script>